//询价单详情/应付报价/应收报价/审核详情1/审核详情2

interface InquiryRatufyDetailViewModel extends ng.IScope {
    /**
     * 附件上传组件
     */
    driverUploader: any;
    
    /**
     * 应付附件信息
     */
    payableAttachUploader:any;
    /**
     * 发货地址省份
     */
    start_provinceCode:string
    /**
     * 发货地址城市
     */
    start_cityCode:string;
    /**
     * 发货地址县区
     */
    start_areaCode:string;
    /**
     * 发货详细地址
     */
    startAddress:string;
    /**
     * 发货地址str
     */
    startAddressStr:string;
    /**
     * 送货地址省份
     */
    end_provinceCode:string
    /**
     * 送货地址城市
     */
    end_cityCode:string;
    /**
     * 送货地址县区
     */
    end_areaCode:string;
    /**
     * 送货详细地址
     */
    endAddress:string;
    /**
     * 送货地址str
     */
    endAddressStr:string;
    /**
     * 填充商务专员下拉
     */
    businessOfficerList: Array<EmployeeListItemResponse>;
    /**
     * 填充客服专员下拉
     */
    customerServiceOfficerList: Array<EmployeeListItemResponse>;
    /**
     * 填充调度专员下拉
     */
    dispatchOfficerList: Array<EmployeeListItemResponse>;
    /**
     * 紧急程度下拉
     */
    urgencyUnitDropDown: ValueListItemResponse[];
    /**
    * 货物重量单位下拉
    */
    goodQuantityUnitDropDown: ValueListItemResponse[];
    /**
    * 所需车型下拉
    */
    carTypeDropDown: ValueListItemResponse[];
    /**
    * 所需车长下拉
    */
    carLengthDropDown: ValueListItemResponse[];
    /**
    * 承运方式下拉
    */
    carrierCategoryDropDown: ValueListItemResponse[];
    /**
    * 应付报价价格单位下拉
    */
    payableQuotationUnitDropDown: ValueListItemResponse[];
    /**
    * 应付保存启用禁用
    */
    saveDis: boolean;
    /**
    * 退回报价
    */
    priceDis: boolean;
    /**
    * 退回下单启用禁用
    */
    orderDis: boolean;
    /**
    * 审核退回
    */
    returnDis: boolean;
    /**
    * 审核通过
    */
    passDis: boolean;
    /**
    * 已中标
    */
    winDis: boolean;
    /**
    * 未中标
    */
    loseDis: boolean;
    /**
    * 中标待定
    */
    pendingDis: boolean;
    /**
    * 调度专员启用/禁用
    */
    dispatchOfficerDis: boolean;
    /**
    * 退回下单按钮显示/消失
    */
    returnOrder: boolean;
    /**
    * 退回报价按钮显示/消失
    */
    returnPrice: boolean;
    /**
    * 应付报价disable
    */
    payInfoDis: boolean;
    /**
    * 禁止输入
    */
    payDisable: boolean;
    /**
    * 变换按钮显示隐藏
    */
    payHide: boolean;
    /**
    * 应收报价隐藏
    */
    receiveHide: boolean;
    /**
    * 确定按钮显示隐藏
    */
    confirm: boolean;
    /**
    * 备注文本域禁用
    */
    remarksDisable: boolean;
    /**
    * 应收单价表单禁用
    */
    receiveDisable: boolean;
    /**
    * 审核通过按钮显示隐藏
    */
    auditPass: boolean;
    /**
    * 审核退回按钮显示隐藏
    */
    auditReturn: boolean;
    /**
    * 已中标按钮显示/隐藏
    */
    win: boolean;
    /**
    * 未中标按钮显示/隐藏
    */
    lose: boolean;
    /**
    * 中标待定按钮显示/隐藏
    */
    pending: boolean;
    /**
    * 询价单页面名称
    */
    inquiryName: string;
    /**
    * 备注显示
    */
    remrksShow: boolean;
    /**
    * 总询价单编号
    */
    inquiryId: string;
    /**
    * 子询价单编号
    */
    inquiryChildId: string;
    /**
    * 下单时间
    */
    createTime: string;
    /**
    * 紧急程度
    */
    urgency: number;
    /**
    * 紧急程度单位
    */
    urgencyUnit: string;
    /**
    * 计划人员名字
    */
    plannerName: string;
    /**
    * 商务专员编号
    */
    businessOfficerId: string;
    /**
    * 商务专员名字
    */
    businessOfficerName: string;
    /**
    * 客服专员编号
    */
    customerServiceOfficerId: string;
    /**
    * 客服专员名字
    */
    customerServiceOfficerName: string;
    /**
    * 调度专员编号
    */
    dispatchOfficerId: string;
    /**
     * 调度专员名称
     */
    dispatchOfficerName:string
    /**
    * 客户单位
    */
    clientName: string;
    /**
    * 发货计划人
    */
    consignorName: string;
    /**
    * 发货人电话
    */
    consignorPhone: string;
    /**
    * 总询价内容
    */
    content: string;
    /**
    * 预计发货时间
    */
    plannedArrivalTime: string;
    /**
    * 预计到货时间
    */
    plannedDeliveryTime: string;
    /**
    * 里程数
    */
    mileage: number;
    /**
    * 货物类别编号
    */
    goodsTypeId: string;
    /**
    * 货物编号
    */
    goodsId: string;
    /**
    * 货物类别
    */
    goodsTypeName: string;
    /**
    * 货物名称
    */
    goodsName: string;
    /**
    * 货物数量
    */
    goodsQuantity: number;
    /**
    * 货物数量单位
    */
    goodsQuantityUnit: string;
    /**
    * 所需车辆
    */
    carType: string;
    /**
    * 所需车长
    */
    carLength: string;
    /**
    * 承运方式
    */
    carrierCategory: string;
    /**
    * 装车效果
    */
    loadingEffect: string;
    /**
    * 附件信息备注
    */
    attachmentDetails: string;
    /**
    * 子单询价备注
    */
    remarks: string;
    /**
    * 应付单价
    */
    payableQuotation: string;
    /**
    * 应付单价2
    */
    payableQuotationTow: string;
    /**
    * 应付单价3
    */
    payableQuotationThree: string;
    /**
    * 应付单价单位
    */
    payableQuotationUnit: string;
    /**
    * 应付单价单位2
    */
    payableQuotationUnitTow: string;
    /**
    * 应付单价单位3
    */
    payableQuotationUnitThree: string;
    /**
    * 应付说明（外付）
    */
    payableQuotationDetails: string;
    /**
    * 应付说明2（外付）
    */
    payableQuotationDetailsTow?: string;
    /**
    * 应付说明3（外付）
    */
    payableQuotationDetailsThree?: string;
    /**
    * 应收单价
    */
    receivableQuotation: number;
    /**
    * 应收单价单位
    */
    receivableQuotationUnit: string;
    /**
    * 应收说明（厂付）
    */
    receivableQuotationDetails: string;
    /**
    * 变换调度员
    */
    changeDispatch: () => void;
    /**
    * 应付保存事件
    */
    confirmC: () => void;
    /**
    * 退回报价事件
    */
    returnPriceC: () => void;
    /**
    * 退回下单事件
    */
    returnOrderC: () => void;
    /**
    * 返回上一层
    */
    cancelC: () => void;
    /**
     * 保存应收价格信息
     */
    receivaSave: () =>void;
    /**
    * 审核通过事件
    */
    auditPassC: () => void;
    /**
    * 审核退回事件
    */
    auditReturnC: () => void;
    /**
    * 已中标事件
    */
    winC: () => void;
    /**
    * 未中标事件
    */
    loseC: () => void;
    /**
    * 待定中标事件
    */
    pendingC: () => void;

    /**
     * 判断调度专员是否下拉
     */
    isShow:boolean;
    /**
     * 图片上传
     */
    handleItemUploader:(item:any)=>void;
    /**
     * 图片删除
     */
    handleItemDelete:(item:any)=>void;
    /**
     * 图片下载
     */
    handleItemDownLoader:(item:any)=>void;
    /**
     * 页面name
     */
    name:string;

}

class InquiryRatufyController {
    uploaderList: AddCarAttachmentDetail[];
    uploaderList2: AddCarAttachmentDetail[];
    baseImageUrl: string;
    /**
     * 询价单编号
     */
    id: string;
    name: string;
    skip:number;
    state:string;

    constructor(private $scope: InquiryRatufyDetailViewModel,
        private routeService: routeService,
        
        private inquiryService: InquiryService,
        private clientService: IClientService,
        private goodsTypeService: IGoodsTypeService,
        private goodsService: IGoodsService,
        private employeeService: IEmployeeService,
        private valueService: IValueService,
        private $ngBootbox: BootboxService,
        private $state: angular.ui.IStateService,
        private $location: ng.ILocationService,
        //  private areaApiService: IAreaService,
        private $http: ng.IHttpService,
        private commonService:ICommonService,
        private $rootScope:ImainRootScope,
        private ossUploaderService:ossUploaderService
    ) {
        this.baseImageUrl = this.routeService.getBaseUrl() + "attachment/";
        this.uploaderList = [];
        this.uploaderList2 = [];
        this.init();
    }

    init = () => {
        this.$scope.isShow = false;
        this.id = this.$location.search().id;
        this.state = this.$location.search().state;
        this.$scope.name= this.name = this.$location.search().name;
        this.skip = this.$location.search().skip;

        this.$scope.receiveDisable = false;
        this.$scope.remarksDisable = false;
        this.$scope.dispatchOfficerDis = true;
        this.$scope.receiveDisable = false;
        this.$scope.confirm = true;


        this.loadValueDropDown();
        



        const OssFile = this.ossUploaderService.getOssFile();
        this.$scope.driverUploader= new OssFile(this.$scope,this.$scope.driverUploader,{uploaderList:this.uploaderList,tag:0,multiple:true});
        this.$scope.driverUploader.onSuccess=(it)=>{
            console.log('onsuccess',it);
            this.onSuccessItem( it.fileName,it.imgSrc,1)

        }

        this.$scope.payableAttachUploader= new OssFile(this.$scope,this.$scope.payableAttachUploader,{uploaderList:this.uploaderList2,tag:1,multiple:true});
        this.$scope.payableAttachUploader.onSuccess=(it)=>{
            console.log('onsuccess',it);
            this.onSuccessItem( it.fileName,it.imgSrc,1)

        }
        this.$scope.payableAttachUploader.onAfterAddingFile = this.handleAddingFile;



        this.$scope.handleItemDownLoader=this.handleItemDownLoader;
        this.$scope.handleItemUploader=this.handleItemUploader;
        this.$scope.handleItemDelete=this.handleItemDelete;


        this.$scope.changeDispatch = this.changeDispatch;

        this.inquiryService.getDetail(this.id).then((res) => {
            var inquiryChildList = res.data.inquiryChildList[0];
            if (inquiryChildList.mileage == 0) {
                inquiryChildList.mileage = null;
            };

            //询价详情
            this.$scope.inquiryId = res.data.inquiryId;
            this.$scope.inquiryChildId = res.data.inquiryChildId;
            this.$scope.createTime = res.data.createTime;
            this.$scope.urgency = res.data.urgency;
            this.$scope.urgencyUnit = res.data.urgencyUnit;
            this.$scope.plannerName = res.data.plannerName;
            this.$scope.businessOfficerId = res.data.businessOfficerId;
            this.$scope.businessOfficerName = res.data.businessOfficerName;
            this.$scope.customerServiceOfficerId = res.data.customerServiceOfficerId;
            this.$scope.customerServiceOfficerName = res.data.customerServiceOfficerName;
            this.$scope.dispatchOfficerId = res.data.dispatchOfficerId;
            this.$scope.dispatchOfficerName = res.data.dispatchOfficerName;



            

            //客户信息
            this.$scope.clientName = res.data.clientName;
            this.$scope.consignorName = res.data.consignorName;
            this.$scope.consignorPhone = res.data.consignorPhone;

            //总询价内容
            this.$scope.content = res.data.content;

            //线路信息
            // this.$scope.start_provinceCode = inquiryChildList.startProvince;
            // this.$scope.start_cityCode = inquiryChildList.startCity;
            // this.$scope.start_areaCode = inquiryChildList.startArea;
            this.$scope.startAddressStr = inquiryChildList.startAddressStr;

            this.$scope.startAddress = inquiryChildList.startAddress;

            // this.$scope.end_provinceCode = inquiryChildList.endProvince;
            // this.$scope.end_cityCode = inquiryChildList.endCity;
            // this.$scope.end_areaCode = inquiryChildList.endArea;
            this.$scope.endAddressStr = inquiryChildList.endAddressStr
            
            this.$scope.endAddress = inquiryChildList.endAddress;

            $(".province").attr("disabled", "disabled");
            $(".city").attr("disabled", "disabled");
            $(".area").attr("disabled", "disabled");


            this.$scope.plannedArrivalTime = inquiryChildList.plannedArrivalTime;
            this.$scope.plannedDeliveryTime = inquiryChildList.plannedDeliveryTime;
            //里程数
            if (inquiryChildList.mileage == null) {
                this.$scope.mileage = 0;
            } else {
                this.$scope.mileage = inquiryChildList.mileage;
            }

            //货物信息
            this.$scope.goodsName = inquiryChildList.goodsName;
            this.$scope.goodsTypeName = inquiryChildList.goodsTypeName;
            this.$scope.goodsQuantity = inquiryChildList.goodsQuantity;
            this.$scope.goodsQuantityUnit = inquiryChildList.goodsQuantityUnit;

            //所需车辆信息
            this.$scope.carType = inquiryChildList.carType;
            this.$scope.carLength = inquiryChildList.carLength;
            this.$scope.carrierCategory = inquiryChildList.carrierCategory;
            this.$scope.loadingEffect = inquiryChildList.loadingEffect;

            //子询价单备注
            this.$scope.remarks = inquiryChildList.remarks;

            //附件信息
            var attachment = res.data.attachment;
            this.$scope.attachmentDetails = res.data.attachmentDetails;
            if (attachment.length > 0) {
                attachment.forEach((item, index) => {
                    // this.commonService.showFileItem(item, this.$scope.driverUploader);
                    this.$scope.driverUploader.addByAttach(item)
                    this.uploaderList.push(item);
                })
            }
            if(this.name == "pay"){
                this.$rootScope.tcr_startAddress=res.data.inquiryChildList[0].startAddressStr;
                this.$rootScope.tcr_endAddress=res.data.inquiryChildList[0].endAddressStr;
                this.$rootScope.tcr_startCityCode=res.data.inquiryChildList[0].startCity;
                this.$rootScope.tcr_endCityCode=res.data.inquiryChildList[0].endCity

                
            }
        }, (rel) => { })

        if (this.name == "pay") {
            this.$scope.confirmC = this.confirmC;
            this.$scope.returnOrderC = this.returnOrderC;
            this.$scope.cancelC = this.cancelC;

            this.$scope.inquiryName = "询价单应付报价";
            this.$scope.remrksShow = true;
            this.$scope.dispatchOfficerDis = false;
            this.$scope.returnOrder = true;

            this.$scope.payInfoDis = false;
            this.$scope.payDisable = true;
            this.$scope.payHide = true;
            this.$scope.receiveHide = false;
            this.loadAllofficerDropDown();
            this.$scope.isShow = true;
            this.payInfo();
            
        } else if (this.name == "receive") {
            this.$scope.confirmC = this.confirmC_receive;
            this.$scope.returnPriceC = this.returnPriceC;
            this.$scope.cancelC = this.cancelC_receive;

            this.$scope.inquiryName = "询价单应收报价";
            this.$scope.returnPrice = true;
            this.$scope.payInfoDis = true;
            this.$scope.receiveHide = true;
            this.$scope.payDisable = true;
            this.$scope.payHide = false;

            this.payInfo();
            if(this.state ==='审核退回'){
                 this.receiveInfo();
            }
        } else if (this.name == 'particularsOne') {
            this.$scope.receivaSave = this.receivaSave;
            this.$scope.auditPassC = this.auditPassC;
            this.$scope.auditReturnC = this.auditReturnC;
            this.$scope.cancelC = this.cancelC_audit;

            this.$scope.inquiryName = "询价单审核详情";
            this.$scope.receiveHide = true;
            this.$scope.payInfoDis = true;
            this.$scope.confirm = false;
            this.$scope.remarksDisable = false;
            this.$scope.receiveDisable = false;
            this.$scope.payDisable = true;
            this.$scope.payHide = false;
            this.$scope.auditPass = true;
            this.$scope.auditReturn = true;

            this.payInfo();
            this.receiveInfo();
        } else if (this.name == 'particularsTow') {
            this.$scope.winC = this.winC;
            this.$scope.loseC = this.loseC;
            this.$scope.pendingC = this.pendingC;
            this.$scope.cancelC = this.cancelC_audit;

            this.$scope.inquiryName = "询价单审核详情";
            this.$scope.receiveHide = true;
            this.$scope.payInfoDis = true;
            this.$scope.confirm = false;
            this.$scope.remarksDisable = false;
            this.$scope.receiveDisable = true;
            this.$scope.payDisable = true;
            this.$scope.payHide = false;
            this.$scope.win = true;
            this.$scope.lose = true;
            this.$scope.pending = true;

            this.payInfo();
            this.receiveInfo();
        } else if (this.name == 'undetermined') {
            this.$scope.winC = this.winC_undetermined;
            this.$scope.loseC = this.loseC_undetermined;
            this.$scope.cancelC = this.cancelC_audit;

            this.$scope.inquiryName = "询价单审核详情";
            this.$scope.receiveHide = true;
            this.$scope.payInfoDis = true;
            this.$scope.confirm = false;
            this.$scope.remarksDisable = false;
            this.$scope.receiveDisable = true;
            this.$scope.payDisable = true;
            this.$scope.payHide = false;
            this.$scope.win = true;
            this.$scope.lose = true;

            this.payInfo();
            this.receiveInfo();
        } else if (this.name == "manage") {
            this.$scope.cancelC = this.cancelC_mange;

            this.$scope.receiveHide = true;
            this.$scope.inquiryName = "询价单详情";
            this.$scope.receiveDisable = true;
            this.$scope.payDisable = true;
            this.$scope.payHide = false;
            this.$scope.remarksDisable = true;
            this.$scope.confirm = false;
            this.$scope.payInfoDis = true;

            this.payInfo();
            this.receiveInfo();
        }

    }

    /** 
     *变换调度事件
     */
    changeDispatch = () => {
        this.inquiryService.dispatch(this.id, parseInt(this.$scope.dispatchOfficerId), $("#dispatchOfficerId option:selected").text()).then((res) => {
            this.$state.go("app.inquiry.InquiryAccept",{ name: "accept" })  //跳转至受理页面,此处路由需要修改
        }, function (rej) { })
    }

    /** 
     *应付保存事件
     */
    confirmC = () => {
        if (!$("#inquiryForm").valid()) { return; };
        this.$scope.saveDis = true;
        if (this.$scope.payableQuotationTow == null && this.$scope.payableQuotationUnitTow == "" && this.$scope.payableQuotationDetailsTow == "" && this.$scope.payableQuotationThree == null && this.$scope.payableQuotationUnitThree == "" && this.$scope.payableQuotationDetailsThree == "") {
            let payableQuotations = [
                {
                    payableQuotation: this.$scope.payableQuotation,
                    payableQuotationUnit: this.$scope.payableQuotationUnit,
                    payableQuotationDetails: this.$scope.payableQuotationDetails,
                }
            ];
        } else if (this.$scope.payableQuotationThree == null && this.$scope.payableQuotationUnitThree == "" && this.$scope.payableQuotationDetailsThree == "") {
            var payableQuotations = [
                {
                    payableQuotation: this.$scope.payableQuotation,
                    payableQuotationUnit: this.$scope.payableQuotationUnit,
                    payableQuotationDetails: this.$scope.payableQuotationDetails,
                },
                {
                    payableQuotation: this.$scope.payableQuotationTow,
                    payableQuotationUnit: this.$scope.payableQuotationUnitTow,
                    payableQuotationDetails: this.$scope.payableQuotationDetailsTow,
                }
            ];
        } else if (this.$scope.payableQuotationTow == null && this.$scope.payableQuotationUnitTow == "" && this.$scope.payableQuotationDetailsTow == "") {
            var payableQuotations = [
                {
                    payableQuotation: this.$scope.payableQuotation,
                    payableQuotationUnit: this.$scope.payableQuotationUnit,
                    payableQuotationDetails: this.$scope.payableQuotationDetails,
                },
                {
                    payableQuotation: this.$scope.payableQuotationThree,
                    payableQuotationUnit: this.$scope.payableQuotationUnitThree,
                    payableQuotationDetails: this.$scope.payableQuotationDetailsThree,
                }
            ];
        } else {
            var payableQuotations = [
                {
                    payableQuotation: this.$scope.payableQuotation,
                    payableQuotationUnit: this.$scope.payableQuotationUnit,
                    payableQuotationDetails: this.$scope.payableQuotationDetails,
                },
                {
                    payableQuotation: this.$scope.payableQuotationTow,
                    payableQuotationUnit: this.$scope.payableQuotationUnitTow,
                    payableQuotationDetails: this.$scope.payableQuotationDetailsTow,
                },
                {
                    payableQuotation: this.$scope.payableQuotationThree,
                    payableQuotationUnit: this.$scope.payableQuotationUnitThree,
                    payableQuotationDetails: this.$scope.payableQuotationDetailsThree,
                }
            ];
        };
        var tempAttachList=this.uploaderList2.map(item=>{
            return [item.attachmentName, item.attachmentPath]
        })
        this.$ngBootbox.confirm('是否确认完成此询价单受理？').then(res => {
            this.inquiryService.addPay(this.id, this.$scope.mileage, payableQuotations, this.$scope.remarks,tempAttachList).then((res)=>{
                this.$scope.saveDis = false;
                this.$state.go("app.inquiry.InquiryAccept",{ name: "accept" });
            }, (rej)=> { this.$scope.saveDis = false; });
        },  ()=> { this.$scope.saveDis = false; return; });
    }

    /** 
     *退回报价事件
     */
    returnPriceC = () => {
        this.$scope.priceDis = true;
        this.$ngBootbox.confirm('确定退回报价吗？').then(() => {
            this.inquiryService.state(this.id, "5", this.$scope.remarks).then((res) => {
                this.$scope.priceDis = false;
                this.$state.go("app.inquiry.Inquiry_receivable", { name: 'receivable' });
            }, (rej) => { this.$scope.priceDis = false; })
        }, () => { this.$scope.priceDis = false; return; });
    }
    /** 
     *退回下单事件
     */
    returnOrderC = () => {
        this.$scope.orderDis = true;
        this.$ngBootbox.confirm('确定退回此单吗？').then(res => {
            this.inquiryService.state(this.id, "3", this.$scope.remarks).then((res) => {
                this.$scope.orderDis = false;
                this.$state.go("app.inquiry.InquiryAccept",{ name: "accept" });//退回至计划处
            }, rel => { this.$scope.orderDis = false; })
        }, rel => { this.$scope.orderDis = false; return; });
    }

    /** 
     *返回询价受理
     */
    cancelC = () => {
        this.$state.go("app.inquiry.InquiryAccept", { name: "accept" });
    }

    /** 
     *应收保存报价
     */
    confirmC_receive = () => {
        if ($("#inquiryForm").valid() == false) { return; };
        this.$scope.saveDis = true;
        /**应收单价集合 */
        var receivableQuotation = {
            receivableQuotation: this.$scope.receivableQuotation,
            receivableQuotationUnit: this.$scope.receivableQuotationUnit,
            receivableQuotationDetails: this.$scope.receivableQuotationDetails
        };
        this.$ngBootbox.confirm('是否完成此询价单的应收报价？').then((res) => {
            this.inquiryService.addReceive(
                this.id,
                receivableQuotation,
                this.$scope.remarks
            ).then((res) => {
                this.$scope.saveDis = false;
                this.$state.go("app.inquiry.Inquiry_receivable", { name: 'receivable' });
            }, (rej) => { this.$scope.saveDis = false; });

        }, (rel) => { this.$scope.saveDis = false; return; })
    }

    /** 
     *退回报价事件
     */
    returnOrderC_receive = () => {
        this.$scope.priceDis = true;
        this.$ngBootbox.confirm('确定退回报价吗？').then((res) => {
            this.inquiryService.state(this.id, "5", this.$scope.remarks).then((res) => {
                this.$scope.priceDis = false;
                this.$state.go("app.inquiry.Inquiry_receivable", { name: 'receivable' });
            }, (rej) => { this.$scope.priceDis = false; })
        }, () => { this.$scope.priceDis = false; return; });
    }

    /** 
     *返回应收
     */
    cancelC_receive = () => {
        this.$state.go("app.inquiry.Inquiry_receivable", { name: 'receivable' });
    }

    /**
     * 保存应收价格信息
     */
    receivaSave = () =>{
        if ($("#inquiryForm").valid() == false) { return; };
        var receivableQuotation = {
            receivableQuotation: this.$scope.receivableQuotation,
            receivableQuotationUnit: this.$scope.receivableQuotationUnit,
            receivableQuotationDetails: this.$scope.receivableQuotationDetails
        };
        this.inquiryService.addReceive(
            this.id,
            receivableQuotation,
            this.$scope.remarks
        ).then((res) => {
            this.$ngBootbox.alert('保存成功！');
        },(rej) => {
        });
    }
    
    /** 
     *审核通过事件
     */
    auditPassC = () => {
       
        this.$scope.passDis = true;
        this.$ngBootbox.confirm('确定审核通过吗？').then((res) => {
            this.inquiryService.state(this.id, "8", this.$scope.remarks).then((res) => {
                this.$scope.passDis = false;
                this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });//审核页面
            }, (rej) => { this.$scope.passDis = false; });
        }, (rej) => { this.$scope.passDis = false; return; });
    }

    /** 
     *审核退回事件
     */
    auditReturnC = () => {
      
        this.$scope.returnDis = true;
        this.$ngBootbox.confirm('确定审核退回吗？').then((res) => {
           
            this.inquiryService.state(this.id, "7", this.$scope.remarks).then((res) => {
                this.$scope.returnDis = false;
                this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });
            }, (rej) => { this.$scope.returnDis = false; });
        }, (rej) => { this.$scope.returnDis = false; return; });
    }

    /** 
     *返回审核
     */
    cancelC_audit = () => {
        this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });
    }

    /** 
     *已中标事件
     */
    winC = () => {
        this.$scope.winDis = true;
        this.$ngBootbox.confirm('确定已中标吗？').then((res) => {
            this.inquiryService.state(this.id, "9", this.$scope.remarks).then((res) => {
                this.$scope.winDis = false;
                this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });//返回审核列表
            }, (rej) => { this.$scope.winDis = false; })
        }, (rej) => { this.$scope.winDis = false; return; });
    }

    //未中标事件
    loseC = () => {
        this.$scope.loseDis = true;
        this.$ngBootbox.confirm('确定未中标吗？').then((res) => {
            this.inquiryService.state(this.id, "10", this.$scope.remarks).then((res) => {
                this.$scope.loseDis = false;
                this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });//返回审核列表
            }, (rej) => { this.$scope.loseDis = false;; })
        }, (rej) => { this.$scope.loseDis = false; return; });
    };

    //中标待定事件
    pendingC = () => {
        this.$scope.pendingDis = true;
        this.$ngBootbox.confirm('确定中标待定吗？').then((res) => {
            this.inquiryService.state(this.id, "11", this.$scope.remarks).then((res) => {
                this.$scope.pendingDis = false;
                this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });//返回审核列表
            }, (rej) => { this.$scope.pendingDis = false; })
        }, (rej) => { this.$scope.pendingDis = false; return; });
    };

    /** 
     *(中标待定)已中标事件
     */
    winC_undetermined = () => {
        this.$scope.winDis = true;
        this.$ngBootbox.confirm('确定已中标吗？').then((res) => {
            this.inquiryService.state(this.id, "9", this.$scope.remarks).then((res) => {
                this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });//返回审核列表
            }, (rej) => { return; })
        }, (rej) => { 
            
            this.$scope.winDis=false;    
        });
    }

    /** 
     *(中标待定)未中标事件
     */
    loseC_undetermined = () => {
        this.$scope.loseDis = true;
        this.$ngBootbox.confirm('确定未中标吗？').then((res) => {
            this.inquiryService.state(this.id, "10", this.$scope.remarks).then((res) => {
                this.$state.go("app.inquiry.inquiryAudit", { name: 'audit' });//返回审核列表
            }, (rej) => { })
        }, () => { 
           this.$scope.loseDis = false;
        });
    };

    /** 
     *(中标待定)未中标事件
     */
    cancelC_mange = () => {
        this.$state.go("app.inquiry.inquiryManagent", { name: 'manage' });//返回审核
    }

    /** 
     *获取应付报价信息
     */
    payInfo = () => {
        this.inquiryService.pay(this.id).then((res) => {
            if (res.data.data.length < 1) { return };
            res.data.data.forEach((item, index) => {
                switch (index) {
                    case 0:
                        item.payableQuotation == null ? this.$scope.payableQuotation = null : this.$scope.payableQuotation = item.payableQuotation;
                        this.$scope.payableQuotationUnit = item.payableQuotationUnit;
                        this.$scope.payableQuotationDetails = item.payableQuotationDetails;
                        break;
                    case 1:
                        item.payableQuotation == null ? this.$scope.payableQuotationTow = null : this.$scope.payableQuotationTow = item.payableQuotation;
                        this.$scope.payableQuotationUnitTow = item.payableQuotationUnit;
                        this.$scope.payableQuotationDetailsTow = item.payableQuotationDetails;
                        break;
                    case 2:
                        item.payableQuotation == null ? this.$scope.payableQuotationThree = null : this.$scope.payableQuotationThree = item.payableQuotation;
                        this.$scope.payableQuotationUnitThree = item.payableQuotationUnit;
                        this.$scope.payableQuotationDetailsThree = item.payableQuotationDetails;
                        break;
                }
            });
            if (res.data.attachment.length > 0) {
                res.data.attachment.forEach((item, index) => {

                    this.commonService.showFileItem(item, this.$scope.payableAttachUploader);
                    this.$scope.payableAttachUploader.addByAttach(item)
                    let attachment = {
                        attachmentId: item[0],
                        attachmentName: item[1],
                        attachmentPath: item[2],
                        attachmentTag: '1'
                    };
                    this.uploaderList2.push(attachment);
                })
            }
        })
    }

    /** 
     *获取应付报价信息
     */
    receiveInfo = () => {
        this.inquiryService.receive(this.id).then((res) => {
            if (res.data === null || res.data === undefined) { return; }
            // if (res.data.receivableQuotation === 0) {
            //     this.$scope.receivableQuotation == null;
            // } else {
            //     this.$scope.receivableQuotation = res.data.receivableQuotation;
            // }
            this.$scope.receivableQuotation = res.data.receivableQuotation;
            this.$scope.receivableQuotationUnit = res.data.receivableQuotationUnit;
            this.$scope.receivableQuotationDetails = res.data.receivableQuotationDetails;
        })
    }

    /** 
     * 填充所有静态下拉事件(除专员已外)
     */
    loadValueDropDown = () => {
        this.$scope.urgencyUnitDropDown = this.valueService.getUrgencyUnitList().data
        this.$scope.goodQuantityUnitDropDown = this.valueService.getGoodQuantityUnitList().data
        this.$scope.carTypeDropDown = this.valueService.getCarTypeList().data
        this.$scope.carLengthDropDown = this.valueService.getCarLengthList().data
        this.$scope.carrierCategoryDropDown = this.valueService.getCarrierWayList().data
        this.$scope.payableQuotationUnitDropDown = this.valueService.getPriceUnitList().data
    }

    /** 
     * 填充所有专员下拉事件
     */
    loadAllofficerDropDown = () => {
        // this.employeeService.getList("5", "", "", "", "",true, 0, -1).then(result => {
        //     this.$scope.businessOfficerList = result.data.data;
        // });

        // this.employeeService.getList("4", "", "", "", "",true, 0, -1).then(result => {
        //     this.$scope.customerServiceOfficerList = result.data.data;
        // });
        
        this.employeeService.getbytype("2", 0, -1).then(result => {
            this.$scope.dispatchOfficerList = result.data.data;
        });

    }


   
    /**
     * 选择上传文件后
     */
    onSuccessItem(fileName: string, filePath: string, tag: number): void {
        let attachment = {
            attachmentId: "",
            attachmentName: fileName,
            attachmentPath: filePath,
            attachmentTag: tag.toString()
        };
        this.uploaderList2.push(attachment);
    }

    /**
     * 过滤图片格式
     */
    // ownFilter(file: File): boolean {
    //     let self:any = this;
    //     return self.queue.length < 10;
    // }

    /**
     * 删除上传的附件
     */
    onDelete(item: any): void {
        $("input[type=file]").val("");
        var imgName = item._file.name;
        this.uploaderList2.forEach((item, index) => {
            if (item.attachmentName == imgName) {
                this.uploaderList2.splice(index, 1);
            }
        });
    }
    handleAddingFile = (item) => {
        console.log('handifeuih');
        
        const ALLOWFILETYPE=['doc', 'docx', 'xls', 'xlsx', 'pdf', 'gif', 'png', 'jpg', 'jpeg','tiff','bmp'];
        
        var fileType = item.fileName.split('.').pop().toLowerCase();
        if(ALLOWFILETYPE.indexOf(fileType) === -1){
            this.$ngBootbox.confirm('不支持该文件类型').then(result => {
                
                this.$scope.payableAttachUploader.onDelete(item);
            },reject=>{
                
                this.$scope.payableAttachUploader.onDelete(item);
            })
        }
        
        
    }
    handleItemUploader = (item) => {
        if(!item.imgSrc){
            item.upload();
        }
        
    }
    handleItemDownLoader = (item) => {
        window.location.href = item.imgSrc;
    }
    handleItemDelete = (item) =>{
        item.remove(),
        this.$scope.payableAttachUploader.onDelete(item);
        
    }

 
}

angular.module("tms").controller("inquiryRatifyController", ["$scope", "routeService", "inquiryService",
    "clientService", "goodsTypeService", "goodsService", "employeeService",
    "valueService", "$ngBootbox", "$state", "$location",
    //"areaApiService",
    "$http","commonService","$rootScope","ossUploaderService", InquiryRatufyController]);
